<!--#
var text = text!"";
var id=id!"";
if(isEmpty(text)&&isNotEmpty(value)){
	//如果没有名称，根据value获取名称，core.getName BeetlConf里添加的自定义方法
	text = address.getName(value+"");
}
 -->
<div class="${style!'layui-input-inline'}" id="${name}Search">
<!--	<input type="text" name="${name}Text" id="${id}Text" style="z-index:2;"  autocomplete="off" class="layui-input" value="${text}" placeholder="选择区域">-->
	<input type="text" name="${name}Text" id="${id}Text" style="position:absolute;z-index:2;" class="layui-input" value="${text}" autocomplete="off" onchange="changeValue(this)" placeholder="选择区域" >
	<select id="${id}address" name="${id}address" lay-verify="" autocomplete="off" lay-filter="${id}address" lay-search="">
	</select>
</div>

<div style="display:none;">
	<input type="text" name='${name}' id="${id}" value="${value!}">
</div>

<div id="${name}TreeDemoContainer">
</div>

<script>
	layui.use(['form', 'layedit','upload'], function () {
		var form = layui.form;
		$(document).ready(function () {
			$("#${name}Search").dblclick(function () {
				Lib.loadAddressPanelBank($("#${id}Text"), $("#${id}"));
			})
		});
		$(document).ready(function () {
			$("#${name}Search").click(
					selectAddressPanel = function () {
						$.ajax({
							url: Common.ctxPath + "/cms/address/bankAddress.json",
							type: "post",
							async: true,
							success: function (callback) {
								var list = callback.data;
								$("#${id}address").empty();
								$("#${id}address").append("<option value=''>请选择</option>");
								for (var i = 0; i < list.length; i++) {
									$("#${id}address").append("<option value=" + list[i].id + ">" + list[i].name + "</option>");
								}
								form.render('select');
							},
							error: function (callback) {
								Common.info(callback.responseJSON.msg);
							}
						});
					}
			)
		});
	})
</script>
<script>
	layui.use(['form','layedit','upload'],function () {
		var form = layui.form;
        form.on('select(${id}address)',function (data) {
			$("#${id}").val(data.value);
			$("#${id}").attr("value",data.value);
			$("#${id}").change();
            var checkText=$("#${id}address").find("option:selected").text();
			// $("#${id}Text").prop("value",checkText);
			$("#${id}Text").val(checkText);
			$("#${id}Text").attr("value",checkText);
			$("#${id}address").next().find("dl").css({"display":"none"});
			form.render();
		});

        var flag = true;
        $("#${id}Text").on('compositionstart',function(){
            flag = false;
        });
        $("#${id}Text").on('compositionend',function(){
            flag = true;
        });
        $("#${id}Text").on('input',function(){
            setTimeout(function(){
                if(flag){
					${id}SearchAddress();
                }
            },0)
        });
        window.changeValue = function(obj){
            $(obj).attr("value",$(obj).val());
        };

		window.${id}SearchAddress = function () {
			var value = $("#${id}Text").val();
            $("#${id}address").val(value);
			form.render();
			$("#${id}address").next().find("dl").css({"display":"block"});
			var dl = $("#${id}address").next().find("dl").children();
			var j = -1;
			for (var i = 0;i < dl.length;i++){
				if (dl[i].innerHTML.indexOf(value) <= -1){
					dl[i].style.display="none";
					j++;
				}
				if (j == dl.length-1 || value == ""){
					$("#${id}address").next().find("dl").css({"display":"none"});
				}
			}
		}
	})
</script>